

#include "stdafx.h"
#include "pf_undoable.h"

#include "pf_undocycle.h"


/**
 * Default constructor.
 */
PF_Undoable::PF_Undoable() {
    cycle = NULL;
}



/**
 * Destructor. Makes sure that this undoable is removed from 
 * its undo cycle before it is deleted.
 */
PF_Undoable::~PF_Undoable() {
    if (cycle!=NULL) {
        cycle->removeUndoable(this);
    }
}



/**
 * Sets the undo cycle this entity is in. This is necessary to
 * make sure the entity can remove itself from the cycle before
 * being deleted.
 */
void PF_Undoable::setUndoCycle(PF_UndoCycle* cycle) {
    this->cycle = cycle;
}



/**
 * The undoable thing gets activated if it was undone and 
 * deactivated otherwise.
 */
void PF_Undoable::changeUndoState() {
    toggleFlag(LX_Define::FlagUndone);
	undoStateChanged(isUndone());
}



/**
 * Undoes or redoes an undoable.
 */
void PF_Undoable::setUndoState(bool undone) {
    if (undone) {
        setFlag(LX_Define::FlagUndone);
    } else {
        delFlag(LX_Define::FlagUndone);
    }
	undoStateChanged(isUndone());
}



/**
 * Is this entity in the Undo memory and not active?
 */
bool PF_Undoable::isUndone() const {
    return getFlag(LX_Define::FlagUndone);
}

